﻿create procedure dbo.GetTakeoutUser
(
		@TakeoutUserID int
	)

AS
	SET NOCOUNT ON 

-- Takeout User

SELECT     Id, TakeoutProviderID, UserID, IsPaid, Instructions, OrderTime, FundsSecuredTime, OrderTotal
FROM         dbo.TakeoutUser
WHERE     (Id = @TakeoutUserID)

-- Order Items

SELECT     Id, TakeoutUserId, MenuItemID, Quantity, Instructions
FROM         dbo.OrderItems
WHERE     (TakeoutUserId = @TakeoutUserID)

-- MenuItems

SELECT     dbo.MenuItems.Id, dbo.MenuItems.MenusId, dbo.MenuItems.Description, dbo.MenuItems.Price, dbo.MenuItems.PrepTimeMinutes
FROM         dbo.MenuItems INNER JOIN
                      dbo.Menus ON dbo.MenuItems.MenusId = dbo.Menus.Id INNER JOIN
                      dbo.TakeoutProvider ON dbo.Menus.Id = dbo.TakeoutProvider.MenuID INNER JOIN
                      dbo.TakeoutUser ON dbo.TakeoutProvider.Id = dbo.TakeoutUser.TakeoutProviderID
WHERE     (dbo.TakeoutUser.Id = @TakeoutUserID)

-- Menus

SELECT     dbo.Menus.Id, dbo.Menus.CategoryId, dbo.Menus.Name, dbo.Menus.Address, dbo.Menus.City, dbo.Menus.State, dbo.Menus.Zipcode, 
                      dbo.Menus.TaxRate
FROM         dbo.Menus INNER JOIN
                      dbo.TakeoutProvider ON dbo.Menus.Id = dbo.TakeoutProvider.MenuID INNER JOIN
                      dbo.TakeoutUser ON dbo.TakeoutProvider.Id = dbo.TakeoutUser.TakeoutProviderID
WHERE     (dbo.TakeoutUser.Id = @TakeoutUserID)

-- Category

SELECT     dbo.Category.Id, dbo.Category.Name, dbo.Category.Description
FROM         dbo.Menus INNER JOIN
                      dbo.TakeoutProvider ON dbo.Menus.Id = dbo.TakeoutProvider.MenuID INNER JOIN
                      dbo.TakeoutUser ON dbo.TakeoutProvider.Id = dbo.TakeoutUser.TakeoutProviderID INNER JOIN
                      dbo.Category ON dbo.Menus.CategoryId = dbo.Category.Id
WHERE     (dbo.TakeoutUser.Id = @TakeoutUserID)

-- TakeoutProvider

SELECT     dbo.TakeoutProvider.Id, dbo.TakeoutProvider.MenuID, dbo.TakeoutProvider.PaymentSourceID, dbo.TakeoutProvider.UserID, 
                      dbo.TakeoutProvider.ExpirationTime, dbo.TakeoutProvider.StartTime, dbo.TakeoutProvider.MaximumOrders, dbo.TakeoutProvider.TakeoutCharge, 
                      dbo.TakeoutProvider.Instructions, dbo.TakeoutProvider.AllowPayMeLater, dbo.TakeoutProvider.[SiteID]
FROM         dbo.TakeoutProvider INNER JOIN
                      dbo.TakeoutUser ON dbo.TakeoutProvider.Id = dbo.TakeoutUser.TakeoutProviderID
WHERE     (dbo.TakeoutUser.Id = @TakeoutUserID)


	RETURN


